/*******************************************************************************
 * Copyright (c) 2007 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     OBEO (www.obeo.fr) - initial API and implementation
 *     CEA List
 *******************************************************************************/
package com.cea.papyrus.extensionpoints.transformation.dialog;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import com.cea.papyrus.extensionpoints.transformation.definition.Transformation;
import com.cea.papyrus.extensionpoints.transformation.validator.TransformationSelectionStatusValidator;

/**
 * The role of this dialog is to select a transformation.
 */
public class SelectTransformationDialog extends ElementTreeSelectionDialog {

	/**
	 * Constructor.
	 * @param pageName name of the page
	 * @param launcherExtension extension of the file to create
	 */
	public SelectTransformationDialog(Shell parentShell, String pageName, String launcherExtension) {
		super(parentShell, new TransformationLabelProvider(), new TransformationContentProvider());
		setTitle(pageName);
		
		// Set dialog properties
		setAllowMultiple(false);
		setDoubleClickSelects(true);
		setHelpAvailable(false);
		setValidator(new TransformationSelectionStatusValidator());
		setEmptyListMessage("No transformation selected.");
		setMessage("Select a transformation:");
		
		// Build input for selection dialog
		// Retrieve Groups and Transformations to show them in the selection dialog
		List<Object> elements = new ArrayList<Object>();
		
		com.cea.papyrus.extensionpoints.transformation.definition.Group[] groups = 
			com.cea.papyrus.extensionpoints.transformation.definition.Group.getRegisteredGroups();
		Transformation[] transfos = Transformation.getRegisteredTransformations();
		
		for (int i = 0 ; i < groups.length ; i++) {
			elements.add(groups[i]);
		}
		
		for (int i = 0 ; i < transfos.length ; i++) {
			elements.add(transfos[i]);
		}

		Object[] elts = elements.toArray(new Object[elements.size()]);
		
		// And set the input in selection tree
		setInput(elts);
	}
}
